-
-
Notifications
You must be signed in to change notification settings - Fork 23
support different languages #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There is a problem: 'jupyter_lang_synonyms' is broken. I will have a look. |
The kernelspec is now determinated with the type of the first code cell
28658c9
to
5e19030
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the kernelspec determination logic to support different programming languages in Jupyter notebooks. Instead of setting the kernelspec at document level based on a default language, it now determines the kernelspec dynamically based on the language of the first code cell encountered.
- Moved kernelspec metadata setting from document level to literal block level
- Added language synonym handling for the first code cell
- Removed static kernelspec assignment in favor of dynamic determination
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
# markup instead. | ||
if self.nodelang != self.langTranslator.translate(self.lang): | ||
# Update metadata | ||
if self.jupyter_kernels is not None and not self.output.metadata: |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition not self.output.metadata
will be false if metadata exists but is empty (e.g., an empty dict). This could prevent kernelspec updates for subsequent code cells. Consider using a more specific check like tracking whether kernelspec has been set.
Copilot uses AI. Check for mistakes.
self.warn( | ||
"Invalid jupyter kernels. " | ||
"jupyter_kernels: {}, lang: {}" | ||
.format(self.jupyter_kernels, self.nodelang)) |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifying self.nodelang
here could have unintended side effects since this variable appears to represent the language of the current node. Consider using a separate variable for the kernelspec language determination.
Copilot uses AI. Check for mistakes.
self.jupyter_kernels[self.nodelang]["kernelspec"] | ||
self.output.metadata["filename"] = self.source_file_name.split("/")[-1] | ||
self.output.metadata["title"] = self.title | ||
except: |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a bare except:
clause catches all exceptions including system exits and keyboard interrupts. Consider catching specific exceptions like KeyError
or AttributeError
instead.
except: | |
except (KeyError, AttributeError, TypeError): |
Copilot uses AI. Check for mistakes.
@djangoliv thanks for your PR. Sorry this repo has been unmaintained for too long. Is this still an issue for you? |
The kernelspec is now determinated with the type of the first code cell.
I want to generate notebooks with different kernel.